﻿using DataBroker.Criteria;
using DataBroker.Dal;
using NorthwindDAO;
using NUnit.Framework;

namespace D2BkTest
{
    [TestFixture    ]
    public class JoinTest
    {
        [SetUp]
        public void SetUp()
        {
            D2Bk.ChangeDatabase("Northwind");
        }
        [Test]
        public void TestJoin()
        {
            var sc = new Filter { MaxRows = 5000 };
            var customers = D2Bk.Fetch(sc, new Customers(new Orders(new Order_details())));
            Assert.AreEqual(2157, customers.Count);
        }
            [Test]
            public void TestJoinInner()
            {
                var sc = new Filter { MaxRows = 5000 };
                var customers = D2Bk.Fetch(sc, new Order_details(new Orders(new Customers ())));
                Assert.AreEqual(2155, customers.Count);
            }
        [Test]
        public void TestJoin2()
        {
            var sc = new Filter();
            sc.AddSorts(new[] { "Customers.Customerid", "Orders.Orderid" });
            sc.MaxRows = 5000;
            var customers = D2Bk.Fetch(sc, new Customers(new Orders(new Order_details())));
            Assert.AreEqual(91, customers.Count);
        }
        [Test]
        public void TestHierarchicalJoin()
        {
            var sc = new Filter { MaxRows = 5000 };
            var customers = D2Bk.Fetch(sc, new Customers(false, new Orders(false, new Order_details())));
            Assert.AreEqual(91, customers.Count);
        }
        [Test]
        public void TestHierarchicalJoin2()
        {
            var sc = new Filter();
            sc.AddSorts(new[] { "Customers.Customerid", "Orders.Orderid" });
            sc.MaxRows = 5000;
            var customers = D2Bk.Fetch(sc, new Customers(false, new Orders(false, new Order_details())));
            Assert.AreEqual(91, customers.Count);
        }
    }
}
